package com.example.checkctf.ProcessorThink;

import android.app.Activity;

import com.example.baselibrary.Bean.CheckTicketBean;
import com.example.baselibrary.Utils.Customer;
import com.example.baselibrary.Utils.LogUtil;
import com.example.baselibrary.Utils.ThreadManager;
import com.example.baselibrary.Utils.TimeUtil;
import com.example.checkctf.NetworkRequest.NetRequestManger;
import com.example.checkctf.NetworkRequest.httpUtils;
import com.google.gson.Gson;

import org.json.JSONObject;

public class QRcodeCheck {

    private static QRcodeCheck instance;
    private CheckTicketBean checkTicketBean;

    public static synchronized QRcodeCheck getInstance() {
        if (null == instance) {
            instance = new QRcodeCheck();
        }
        return instance;
    }

    public void checkTicketNeedFace(final String searchType, final String s, final String rowkey) {
//        if (null == checkTicketBean) {
//            checkTicketBean = new CheckTicketBean();
//
//        }

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                NetRequestManger.getInstance().netRequest(searchType,s,-1,rowkey,TimeUtil.convertTime(TimeUtil.FORMAT_DAY_EN_ZYF, System.currentTimeMillis()));
            }
        };
        ThreadManager.getThreadPool().execute(runnable);

//        checkTicketBean.setSearchDataType("1"); //参数类型（1.二维码2.身份证3.卡号4.人脸）
//        checkTicketBean.setSearchData(s);//参数值（searchDataType对应的值） 就是读卡或者身份证读取出来的信息
//        checkTicketBean.setCheckCount(-1);//检票数量（-1为全检）
////        checkTicketBean.setGateNo((String) SPUtils.get(context, Customer.CONFIG_GATE_NO,""));//闸机编号
//        checkTicketBean.setGateNo("A001001G001");//闸机编号
//        checkTicketBean.setIsCollectionGate("Y");  //是否是采集人脸闸机（Y：是，N：否）
//        checkTicketBean.setRowKey("1111111"); //人脸唯一标识，在采集成功和1:1比对成功后必传
//        checkTicketBean.setSign("A96D48AE69F46BD0E1B17F10316086F3");  //签名
//        checkTicketBean.setTimestamp(TimeUtil.convertTime(TimeUtil.FORMAT_DAY_EN_ZYF, System.currentTimeMillis()));//接口调用时的时间，格式“yyyyMMddHHmmss”
//        ObserverOnNextListener<CheckResultBean> listener = new ObserverOnNextListener<CheckResultBean>() {
//            @Override
//            public void onNext(CheckResultBean checkTicketBean) {
//                //处理结果信息
//                switch (checkTicketBean.getCode()) {
//                    case ResultCode.SUCCESS: //0-接口调用成功,即检票成功
//                        break;
//                    case ResultCode.TO_COLLECT_INFORMATION://进行闸机采集信息,调用1.2采集接口，采集成功后将人脸id加到检票参数中，重新检票
//                        //去采集人脸信息
//                        break;
//                }
//            }
//        };
//        String json = new Gson().toJson(checkTicketBean);
//        LogUtil.v(json);
////        ApiMethods.checkTicket(new ProgressObserver<CheckResultBean>(context, listener), "1", "A82EC318A954A6F0E", -1, "A001001G001", "Y", "", "", TimeUtil.convertTime(TimeUtil.FORMAT_DAY_EN_ZYF, System.currentTimeMillis()));
//        ApiMethods.checkTicketJson(new ProgressObserver<CheckResultBean>(context, listener), checkTicketBean);

//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                // 先封装一个 JSON 对象
//                JSONObject param = new JSONObject();
//
//                try {
//                    param.put("searchDataType", "1");
//                    param.put("searchData", s);
//                    param.put("checkCount", -1);
//                    param.put("gateNo", "A001001G001");
//                    param.put("isCollectionGate", "N");
//                    param.put("sign", "A96D48AE69F46BD0E1B17F10316086F3");
//                    param.put("timestamp", "20180611165000");
//
////                    String ss = httpUtils.postJson(BaseUrl.check_Ticket_or_Card, param);
//                    String url = Customer.BASE_URL + Customer.CHECK_ALL_URL;
//                    String ss = httpUtils.postJson(url, param);
//                    LogUtil.v("飞机" + ss);
//                } catch (Exception e) {
//                    LogUtil.v("飞机" + "aaaaaa");
//                }
//            }
//        }).start();




    }
}
